<?php
class Admin_MediaController extends Zend_Controller_Action
{
	private $model;
	public function init()
	{
		$this->model = new Admin_Model_Media();
		$dirfile = $this->_request->getBaseUrl() . "/application/layouts/admin";
		$dirlayout = APPLICATION_PATH . "/layouts/admin";
		$this->view->imgs = $dirfile . "/images";
		$this->view->headLink()->appendStylesheet($dirfile . '/css/style.css');
		$this->view->headLink()->appendStylesheet($dirfile . '/css/jquery-ui-1.8.18.custom.css');
		$this->view->headLink()->appendStylesheet($dirfile . '/css/jquery.treeview.css');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery-1.7.2.min.js');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery-ui-1.8.18.custom.min.js');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery.treeview.js');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery.treeview.async.js');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery.treeview.edit.js');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery.treeview.sortable.js');
		$this->view->headScript()->appendFile($dirfile . '/js/dropdown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/slidedown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/treeview.js');
		$this->view->headScript()->appendFile($dirfile . '/js/delimg.js');
		$this->view->headScript()->appendFile($dirfile . '/js/delvideo.js');
		$option = array('layoutPath'=>$dirlayout,'layout'=>'index');
		Zend_Layout::startMvc($option);
	}
	public function indexAction()
	{
			
	}
	public function getsearchimgAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$contents = $this->_request->getParam('text-search');
		$session = new Zend_Session_Namespace('searchimg');
		$session->content = $contents;
		$this->_forward('searchimg');
	}
	public function searchimgAction()
	{
		$session = new Zend_Session_Namespace('searchimg');
		$contents = $session->content;
		$search = $this->model->searchimg($contents);
		$pagingsearch = Zend_Paginator::factory($search);
		$pagingsearch->setItemCountPerPage(2);
		$pagingsearch->setPageRange(3);
		$currentsearch = $this->_request->getParam('page',1);
		$pagingsearch->setCurrentPageNumber($currentsearch);
		$this->view->pagingsearch = $pagingsearch;
	}
	public function manageimgAction()
	{
		$data = $this->model->getallimg();
		$paging = Zend_Paginator::factory($data);
		$paging->setItemCountPerPage(2);
		$paging->setPageRange(2);
		$current = $this->_request->getParam('page',1);
		$paging->setCurrentPageNumber($current);
		$this->view->paging = $paging;
	}
	public function managevideoAction()
	{
		$data = $this->model->getallvideo();
		$paging = Zend_Paginator::factory($data);
		$paging->setItemCountPerPage(2);
		$paging->setPageRange(2);
		$current = $this->_request->getParam('page',1);
		$paging->setCurrentPageNumber($current);
		$this->view->paging = $paging;
	}
	public function getsearchvideoAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$contents = $this->_request->getParam('text-search');
		$session = new Zend_Session_Namespace('searchvideo');
		$session->content = $contents;
		$this->_forward('searchvideo');
	}public function searchvideoAction()
	{
		$session = new Zend_Session_Namespace('searchvideo');
		$contents = $session->content;
		$search = $this->model->searchvideo($contents);
		$pagingsearch = Zend_Paginator::factory($search);
		$pagingsearch->setItemCountPerPage(2);
		$pagingsearch->setPageRange(3);
		$currentsearch = $this->_request->getParam('page',1);
		$pagingsearch->setCurrentPageNumber($currentsearch);
		$this->view->pagingsearch = $pagingsearch;
	}
	public function delimgAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$id = $this->_request->getParam('id');
		try {
			$delete = $this->model->delimg($id);
		}catch(Zend_Db_Exception $e)
		{
			echo "Loi xu ly";
		}
	}
	public function delvideoAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$id = $this->_request->getParam('id');
		try {
			$delete = $this->model->delvideo($id);
		}catch (Zend_Db_Exception $e)
		{
			echo "Loi xu ly";
		}
	}
}